package com.smart.community.security.service;

import com.smart.community.commons.base.BaseEntity;
import com.smart.community.commons.result.PageResult;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 安防管理Service接口
 * 提供门禁控制、监控管理、巡逻记录等相关的业务操作
 * 
 * @author Wu.Liang
 * @version 1.0.0
 * @since 2024-12-19
 */
public interface ISecurityService {
    
    // ========================= 门禁管理 =========================
    
    /**
     * 添加门禁设备
     * @param device 设备信息
     * @return 设备ID
     */
    Long addAccessDevice(AccessDevice device);
    
    /**
     * 根据社区ID查询门禁设备
     * @param communityId 社区ID
     * @return 设备列表
     */
    List<AccessDevice> getAccessDevicesByCommunityId(Long communityId);
    
    /**
     * 记录门禁通行
     * @param accessRecord 通行记录
     * @return 记录ID
     */
    Long recordAccess(AccessRecord accessRecord);
    
    /**
     * 分页查询门禁记录
     * @param current 当前页
     * @param size 每页大小
     * @param communityId 社区ID
     * @param deviceId 设备ID
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 分页结果
     */
    PageResult<AccessRecord> pageAccessRecords(Integer current, Integer size,
            Long communityId, Long deviceId,
            LocalDateTime startTime, LocalDateTime endTime);
    
    /**
     * 用户门禁权限验证
     * @param userId 用户ID
     * @param deviceId 设备ID
     * @return 是否有权限
     */
    boolean verifyAccessPermission(Long userId, Long deviceId);
    
    // ========================= 监控管理 =========================
    
    /**
     * 添加监控设备
     * @param camera 监控设备信息
     * @return 设备ID
     */
    Long addSurveillanceCamera(SurveillanceCamera camera);
    
    // ========================= 巡逻管理 =========================
    
    /**
     * 创建巡逻任务
     * @param patrolTask 巡逻任务
     * @return 任务ID
     */
    Long createPatrolTask(PatrolTask patrolTask);
    
    /**
     * 记录巡逻检查点
     * @param checkRecord 检查记录
     * @return 记录ID
     */
    Long recordPatrolCheck(PatrolCheckRecord checkRecord);
    
    /**
     * 分页查询巡逻记录
     * @param current 当前页
     * @param size 每页大小
     * @param communityId 社区ID
     * @param patrolmanId 巡逻员ID
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 分页结果
     */
    PageResult<PatrolRecord> pagePatrolRecords(Integer current, Integer size,
            Long communityId, Long patrolmanId,
            LocalDateTime startTime, LocalDateTime endTime);
    
    // ========================= 安全告警 =========================
    
    /**
     * 记录监控告警
     * @param alert 告警信息
     * @return 告警ID
     */
    Long recordAlert(SecurityAlert alert);
    
    /**
     * 处理安全告警
     * @param alertId 告警ID
     * @param handlerId 处理人ID
     * @param handleResult 处理结果
     * @return 是否处理成功
     */
    boolean handleAlert(Long alertId, Long handlerId, String handleResult);
    
    /**
     * 分页查询安全告警
     * @param current 当前页
     * @param size 每页大小
     * @param communityId 社区ID
     * @param alertType 告警类型
     * @param status 处理状态
     * @return 分页结果
     */
    PageResult<SecurityAlert> pageSecurityAlerts(Integer current, Integer size,
            Long communityId, String alertType, Integer status);
    
    // ========================= 访客管理 =========================
    
    /**
     * 访客预约
     * @param visitor 访客信息
     * @return 预约ID
     */
    Long makeVisitorAppointment(Visitor visitor);
    
    /**
     * 访客签到
     * @param visitorId 访客ID
     * @return 是否签到成功
     */
    boolean checkInVisitor(Long visitorId);
    
    /**
     * 访客签退
     * @param visitorId 访客ID
     * @return 是否签退成功
     */
    boolean checkOutVisitor(Long visitorId);
    
    /**
     * 分页查询访客记录
     * @param current 当前页
     * @param size 每页大小
     * @param communityId 社区ID
     * @param status 访客状态
     * @return 分页结果
     */
    PageResult<Visitor> pageVisitors(Integer current, Integer size,
            Long communityId, Integer status);
    
    // ========================= 统计分析 =========================
    
    /**
     * 获取安防统计信息
     * @param communityId 社区ID
     * @param startTime 开始时间
     * @param endTime 结束时间
     * @return 统计信息
     */
    SecurityStatistics getSecurityStatistics(Long communityId, LocalDateTime startTime, LocalDateTime endTime);
    
    // ========================= 内部类定义 =========================
    
    /**
     * 门禁设备
     */
    class AccessDevice extends BaseEntity {
        private String deviceCode;
        private String deviceName;
        private Integer deviceType;
        private String location;
        private Long communityId;
        private Integer status;
        
        // getter/setter methods
        public String getDeviceCode() { return deviceCode; }
        public void setDeviceCode(String deviceCode) { this.deviceCode = deviceCode; }
        
        public String getDeviceName() { return deviceName; }
        public void setDeviceName(String deviceName) { this.deviceName = deviceName; }
        
        public Integer getDeviceType() { return deviceType; }
        public void setDeviceType(Integer deviceType) { this.deviceType = deviceType; }
        
        public String getLocation() { return location; }
        public void setLocation(String location) { this.location = location; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
        
        public Integer getStatus() { return status; }
        public void setStatus(Integer status) { this.status = status; }
    }
    
    /**
     * 门禁记录
     */
    class AccessRecord extends BaseEntity {
        private Long userId;
        private Long deviceId;
        private String accessType;
        private String accessMethod;
        private Integer accessResult;
        private LocalDateTime accessTime;
        private Long communityId;
        
        // getter/setter methods
        public Long getUserId() { return userId; }
        public void setUserId(Long userId) { this.userId = userId; }
        
        public Long getDeviceId() { return deviceId; }
        public void setDeviceId(Long deviceId) { this.deviceId = deviceId; }
        
        public String getAccessType() { return accessType; }
        public void setAccessType(String accessType) { this.accessType = accessType; }
        
        public String getAccessMethod() { return accessMethod; }
        public void setAccessMethod(String accessMethod) { this.accessMethod = accessMethod; }
        
        public Integer getAccessResult() { return accessResult; }
        public void setAccessResult(Integer accessResult) { this.accessResult = accessResult; }
        
        public LocalDateTime getAccessTime() { return accessTime; }
        public void setAccessTime(LocalDateTime accessTime) { this.accessTime = accessTime; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
    }
    
    /**
     * 监控摄像头
     */
    class SurveillanceCamera extends BaseEntity {
        private String cameraCode;
        private String cameraName;
        private String location;
        private String streamUrl;
        private Long communityId;
        private Integer status;
        
        // getter/setter methods
        public String getCameraCode() { return cameraCode; }
        public void setCameraCode(String cameraCode) { this.cameraCode = cameraCode; }
        
        public String getCameraName() { return cameraName; }
        public void setCameraName(String cameraName) { this.cameraName = cameraName; }
        
        public String getLocation() { return location; }
        public void setLocation(String location) { this.location = location; }
        
        public String getStreamUrl() { return streamUrl; }
        public void setStreamUrl(String streamUrl) { this.streamUrl = streamUrl; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
        
        public Integer getStatus() { return status; }
        public void setStatus(Integer status) { this.status = status; }
    }
    
    /**
     * 巡逻任务
     */
    class PatrolTask extends BaseEntity {
        private String taskName;
        private String routeDescription;
        private LocalDateTime startTime;
        private LocalDateTime endTime;
        private Long patrolmanId;
        private Long communityId;
        private Integer status;
        
        // getter/setter methods
        public String getTaskName() { return taskName; }
        public void setTaskName(String taskName) { this.taskName = taskName; }
        
        public String getRouteDescription() { return routeDescription; }
        public void setRouteDescription(String routeDescription) { this.routeDescription = routeDescription; }
        
        public LocalDateTime getStartTime() { return startTime; }
        public void setStartTime(LocalDateTime startTime) { this.startTime = startTime; }
        
        public LocalDateTime getEndTime() { return endTime; }
        public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; }
        
        public Long getPatrolmanId() { return patrolmanId; }
        public void setPatrolmanId(Long patrolmanId) { this.patrolmanId = patrolmanId; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
        
        public Integer getStatus() { return status; }
        public void setStatus(Integer status) { this.status = status; }
    }
    
    /**
     * 巡逻记录
     */
    class PatrolRecord extends BaseEntity {
        private Long taskId;
        private Long patrolmanId;
        private Long communityId;
        private LocalDateTime startTime;
        private LocalDateTime endTime;
        private String summary;
        private Integer status;
        
        // getter/setter methods
        public Long getTaskId() { return taskId; }
        public void setTaskId(Long taskId) { this.taskId = taskId; }
        
        public Long getPatrolmanId() { return patrolmanId; }
        public void setPatrolmanId(Long patrolmanId) { this.patrolmanId = patrolmanId; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
        
        public LocalDateTime getStartTime() { return startTime; }
        public void setStartTime(LocalDateTime startTime) { this.startTime = startTime; }
        
        public LocalDateTime getEndTime() { return endTime; }
        public void setEndTime(LocalDateTime endTime) { this.endTime = endTime; }
        
        public String getSummary() { return summary; }
        public void setSummary(String summary) { this.summary = summary; }
        
        public Integer getStatus() { return status; }
        public void setStatus(Integer status) { this.status = status; }
    }
    
    /**
     * 巡逻检查记录
     */
    class PatrolCheckRecord extends BaseEntity {
        private Long taskId;
        private String checkPoint;
        private LocalDateTime checkTime;
        private String checkResult;
        private String photos;
        private Long communityId;
        
        // getter/setter methods
        public Long getTaskId() { return taskId; }
        public void setTaskId(Long taskId) { this.taskId = taskId; }
        
        public String getCheckPoint() { return checkPoint; }
        public void setCheckPoint(String checkPoint) { this.checkPoint = checkPoint; }
        
        public LocalDateTime getCheckTime() { return checkTime; }
        public void setCheckTime(LocalDateTime checkTime) { this.checkTime = checkTime; }
        
        public String getCheckResult() { return checkResult; }
        public void setCheckResult(String checkResult) { this.checkResult = checkResult; }
        
        public String getPhotos() { return photos; }
        public void setPhotos(String photos) { this.photos = photos; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
    }
    
    /**
     * 安全告警
     */
    class SecurityAlert extends BaseEntity {
        private String alertCode;
        private String alertType;
        private String alertContent;
        private Integer severity;
        private Long deviceId;
        private Long communityId;
        private Long handlerId;
        private String handleResult;
        private Integer status;
        
        // getter/setter methods
        public String getAlertCode() { return alertCode; }
        public void setAlertCode(String alertCode) { this.alertCode = alertCode; }
        
        public String getAlertType() { return alertType; }
        public void setAlertType(String alertType) { this.alertType = alertType; }
        
        public String getAlertContent() { return alertContent; }
        public void setAlertContent(String alertContent) { this.alertContent = alertContent; }
        
        public Integer getSeverity() { return severity; }
        public void setSeverity(Integer severity) { this.severity = severity; }
        
        public Long getDeviceId() { return deviceId; }
        public void setDeviceId(Long deviceId) { this.deviceId = deviceId; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
        
        public Long getHandlerId() { return handlerId; }
        public void setHandlerId(Long handlerId) { this.handlerId = handlerId; }
        
        public String getHandleResult() { return handleResult; }
        public void setHandleResult(String handleResult) { this.handleResult = handleResult; }
        
        public Integer getStatus() { return status; }
        public void setStatus(Integer status) { this.status = status; }
    }
    
    /**
     * 访客
     */
    class Visitor extends BaseEntity {
        private String visitorName;
        private String visitorPhone;
        private String idCard;
        private String purpose;
        private LocalDateTime appointmentTime;
        private LocalDateTime checkinTime;
        private LocalDateTime checkoutTime;
        private Long hostUserId;
        private Long communityId;
        private Integer status;
        
        // getter/setter methods
        public String getVisitorName() { return visitorName; }
        public void setVisitorName(String visitorName) { this.visitorName = visitorName; }
        
        public String getVisitorPhone() { return visitorPhone; }
        public void setVisitorPhone(String visitorPhone) { this.visitorPhone = visitorPhone; }
        
        public String getIdCard() { return idCard; }
        public void setIdCard(String idCard) { this.idCard = idCard; }
        
        public String getPurpose() { return purpose; }
        public void setPurpose(String purpose) { this.purpose = purpose; }
        
        public LocalDateTime getAppointmentTime() { return appointmentTime; }
        public void setAppointmentTime(LocalDateTime appointmentTime) { this.appointmentTime = appointmentTime; }
        
        public LocalDateTime getCheckinTime() { return checkinTime; }
        public void setCheckinTime(LocalDateTime checkinTime) { this.checkinTime = checkinTime; }
        
        public LocalDateTime getCheckoutTime() { return checkoutTime; }
        public void setCheckoutTime(LocalDateTime checkoutTime) { this.checkoutTime = checkoutTime; }
        
        public Long getHostUserId() { return hostUserId; }
        public void setHostUserId(Long hostUserId) { this.hostUserId = hostUserId; }
        
        public Long getCommunityId() { return communityId; }
        public void setCommunityId(Long communityId) { this.communityId = communityId; }
        
        public Integer getStatus() { return status; }
        public void setStatus(Integer status) { this.status = status; }
    }
    
    /**
     * 安防统计
     */
    class SecurityStatistics {
        private Integer totalAccessRecords;
        private Integer totalAlerts;
        private Integer totalPatrols;
        private Integer totalVisitors;
        private Integer unhandledAlerts;
        private Integer handledAlerts;
        private Integer completedPatrols;
        private Integer checkPointCount;
        private Double alertHandleRate;
        private Double patrolCompletionRate;
        
        // getter/setter methods
        public Integer getTotalAccessRecords() { return totalAccessRecords; }
        public void setTotalAccessRecords(Integer totalAccessRecords) { this.totalAccessRecords = totalAccessRecords; }
        
        public Integer getTotalAlerts() { return totalAlerts; }
        public void setTotalAlerts(Integer totalAlerts) { this.totalAlerts = totalAlerts; }
        
        public Integer getTotalPatrols() { return totalPatrols; }
        public void setTotalPatrols(Integer totalPatrols) { this.totalPatrols = totalPatrols; }
        
        public Integer getTotalVisitors() { return totalVisitors; }
        public void setTotalVisitors(Integer totalVisitors) { this.totalVisitors = totalVisitors; }
        
        public Integer getUnhandledAlerts() { return unhandledAlerts; }
        public void setUnhandledAlerts(Integer unhandledAlerts) { this.unhandledAlerts = unhandledAlerts; }
        
        public Integer getHandledAlerts() { return handledAlerts; }
        public void setHandledAlerts(Integer handledAlerts) { this.handledAlerts = handledAlerts; }
        
        public Integer getCompletedPatrols() { return completedPatrols; }
        public void setCompletedPatrols(Integer completedPatrols) { this.completedPatrols = completedPatrols; }
        
        public Integer getCheckPointCount() { return checkPointCount; }
        public void setCheckPointCount(Integer checkPointCount) { this.checkPointCount = checkPointCount; }
        
        public Double getAlertHandleRate() { return alertHandleRate; }
        public void setAlertHandleRate(Double alertHandleRate) { this.alertHandleRate = alertHandleRate; }
        
        public Double getPatrolCompletionRate() { return patrolCompletionRate; }
        public void setPatrolCompletionRate(Double patrolCompletionRate) { this.patrolCompletionRate = patrolCompletionRate; }
    }
}
